package com.ruoyi.web.controller.product;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.ProductImg;
import com.ruoyi.product.service.IProductImgService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品图片Controller
 *
 * @author tanfp
 * @date 2020-12-27
 */
@Controller
@RequestMapping("/product/productImg")
public class ProductImgController extends BaseController {
    private String prefix = "product/productImg";

    @Autowired
    private IProductImgService productImgService;

    @RequiresPermissions("product:productImg:view")
    @GetMapping()
    public String productImg() {
        return prefix + "/productImg";
    }

            /**
         * 查询商品图片列表
         */
        @RequiresPermissions("product:productImg:list")
        @PostMapping("/list")
        @ResponseBody
        public TableDataInfo list(ProductImg productImg) {
            startPage();
            List<ProductImg> list = productImgService.selectProductImgList(productImg);
            return getDataTable(list);
        }
    
    /**
     * 导出商品图片列表
     */
    @RequiresPermissions("product:productImg:export")
    @Log(title = "商品图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductImg productImg) {
        List<ProductImg> list = productImgService.selectProductImgList(productImg);
        ExcelUtil<ProductImg> util = new ExcelUtil<ProductImg>(ProductImg. class);
        return util.exportExcel(list, "productImg");
    }

            /**
         * 新增商品图片
         */
        @GetMapping("/add")
        public String add() {
            return prefix + "/add";
        }
    
    /**
     * 新增保存商品图片
     */
    @RequiresPermissions("product:productImg:add")
    @Log(title = "商品图片", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductImg productImg) {
        return toAjax(productImgService.insertProductImg(productImg));
    }

    /**
     * 修改商品图片
     */
    @GetMapping("/edit/{keyId}")
    public String edit(@PathVariable("keyId") Long keyId, ModelMap mmap) {
        ProductImg productImg =productImgService.selectProductImgById(keyId);
        mmap.put("productImg", productImg);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品图片
     */
    @RequiresPermissions("product:productImg:edit")
    @Log(title = "商品图片", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductImg productImg) {
        return toAjax(productImgService.updateProductImg(productImg));
    }

            /**
         * 删除商品图片
         */
        @RequiresPermissions("product:productImg:remove")
        @Log(title = "商品图片", businessType = BusinessType.DELETE)
        @PostMapping("/remove")
        @ResponseBody
        public AjaxResult remove(String ids) {
            return toAjax(productImgService.deleteProductImgByIds(ids));
        }
        }
